package org.apache.james.hibernate.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;

@Entity
@Table(name="Mailbox")
public class DbMailbox {
	int id;
	
	long version;
	long uid;
	
	long uidValidity;
	
	String name;
	
	ImapUserInfo owner;
	
	NamespaceImpl namespace;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	@Version
	public long getVersion() {
		return version;
	}
	
	public void setVersion(long version) {
		this.version = version;
	}
	
	@Column(name="uid_col")
	public long getUid() {
		return uid;
	}

	public void setUid(long uid) {
		this.uid = uid;
	}
	
	public long getUidValidity() {
		return uidValidity;
	}
	
	public void setUidValidity(long uidValidity) {
		this.uidValidity = uidValidity;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@ManyToOne(optional = true, fetch = FetchType.LAZY)
	public ImapUserInfo getOwner() {
		return owner;
	}

	public void setOwner(ImapUserInfo owner) {
		this.owner = owner;
	}
	
	@ManyToOne(optional = false, cascade = {}, fetch = FetchType.LAZY)
	public NamespaceImpl getNamespace() {
		return namespace;
	}
	
	public void setNamespace(NamespaceImpl namespace) {
		this.namespace = namespace;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == this) {
			return true;
		}
		if (obj instanceof DbMailbox) {
			return ((DbMailbox)obj).getId()==getId();
		}
		return super.equals(obj);
	}

}
